#pragma once

#include "RemoveStructuralFeatureValueAction.h"

#include "InputPin.h"

namespace uml {

const bool RemoveStructuralFeatureValueAction::isRemoveDuplicates_default_ = false;
RemoveStructuralFeatureValueAction::RemoveStructuralFeatureValueAction(const QString& umlType)
    : WriteStructuralFeatureAction(umlType) {}

void RemoveStructuralFeatureValueAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    WriteStructuralFeatureAction::fromJson(json, errorList);
    isRemoveDuplicates_ = json.value("isRemoveDuplicates").toBool(isRemoveDuplicates_default_);
    removeAt_ = JsonSerializable::create<InputPin>(json.value("removeAt"), errorList);

}

void RemoveStructuralFeatureValueAction::toJson(QJsonObject& json) {
    WriteStructuralFeatureAction::toJson(json);
    if (isRemoveDuplicates_ != isRemoveDuplicates_default_) {
        json.insert("isRemoveDuplicates", isRemoveDuplicates_);
    }
    if (removeAt_) {
        QJsonObject removeAt_json;
        removeAt_->toJson(removeAt_json);
        json.insert("removeAt", removeAt_json);
    }
}

/// <summary>
/// isRemoveDuplicates getter
/// Specifies whether to remove duplicates of the value in nonunique
/// StructuralFeatures.
/// </summary>
bool RemoveStructuralFeatureValueAction::isRemoveDuplicates() const {
    return isRemoveDuplicates_;
}

/// <summary>
/// isRemoveDuplicates setter
/// Specifies whether to remove duplicates of the value in nonunique
/// StructuralFeatures.
/// </summary>
void RemoveStructuralFeatureValueAction::setIsRemoveDuplicates(bool value) {
    isRemoveDuplicates_ = value;
}

/// <summary>
/// removeAt getter
/// An InputPin that provides the position of an existing value to remove in
/// ordered, nonunique structural features. The type of the removeAt InputPin is
/// UnlimitedNatural, but the value cannot be zero or unlimited.
/// </summary>
shared_ptr<InputPin> RemoveStructuralFeatureValueAction::removeAt() const {
    return removeAt_;
}

/// <summary>
/// removeAt setter
/// An InputPin that provides the position of an existing value to remove in
/// ordered, nonunique structural features. The type of the removeAt InputPin is
/// UnlimitedNatural, but the value cannot be zero or unlimited.
/// </summary>
void RemoveStructuralFeatureValueAction::setRemoveAt(shared_ptr<InputPin> value) {
    removeAt_ = value;
}

} // namespace uml
